package container

import "gitee.com/hasika/gotool/generic"

func SetToArray[T comparable](m map[T]struct{}) []T {
	ret := make([]T, 0, len(m))
	for k := range m {
		ret = append(ret, k)
	}
	return ret
}

func MapKeyToArray[T comparable, R any](m map[T]R) []T {
	ret := make([]T, 0, len(m))
	for k := range m {
		ret = append(ret, k)
	}
	return ret
}

func ArrayToSet[T comparable](m []T) map[T]struct{} {
	ret := make(map[T]struct{}, len(m))
	for _, k := range m {
		ret[k] = struct{}{}
	}
	return ret
}

func NumberArrayConvert[T generic.Number, H generic.Number](from []T) []H {
	ret := make([]H, 0, len(from))
	for _, v := range from {
		ret = append(ret, H(v))
	}
	return ret
}
